﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Odense_Kommune.Controller;

namespace Odense_Kommune
{
    /// <summary>
    /// Interaction logic for Login.xaml - Kodet af Tien
    /// </summary>
    public partial class Login : Window
    {
        public Login()
        {
            InitializeComponent();
            txtEmail.Focus();
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (txtEmail.Text.Length > 0)
                MessageBox.Show("Hej " + txtEmail.Text);
        }

        private void SocialCentret()
        {
            Socialcentret vindue = new Socialcentret(); this.Close();
            vindue.ShowDialog();
        }

        private void SocialArbejder()
        {
            Socialarbejder vindue = new Socialarbejder();
            this.Close();
            vindue.Show();
        }

        #region Knap Metoder
        private void btnSocialCentret_Click(object sender, RoutedEventArgs e) { SocialCentret(); }

        private void btnSocialarbejder_Click(object sender, RoutedEventArgs e) { SocialArbejder(); }
        #endregion

        private void txtEmail_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!Validering.Email(txtEmail.Text))
            {
                //position for markør
                int cursorPosition = txtEmail.SelectionStart - 1;

                //fjerner uønskede tegn
                txtEmail.Text = Validering.ValiderEmail(txtEmail.Text);

                //fokus på textbox
                txtEmail.Focus();

                //ny position for markør efter fjernelse af uønsket tegn
                txtEmail.Select(cursorPosition, 0);
            }
        }
    }
}
